package com.dxyusn.schedule.elasticjob.standalone.script;

import org.apache.shardingsphere.elasticjob.api.JobConfiguration;
import org.apache.shardingsphere.elasticjob.lite.api.bootstrap.impl.ScheduleJobBootstrap;
import org.apache.shardingsphere.elasticjob.reg.base.CoordinatorRegistryCenter;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperConfiguration;
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter;
import org.apache.shardingsphere.elasticjob.script.props.ScriptJobProperties;

public class ScriptJobTest
{
    public static void main(String[] args)
    {
        ScheduleJobBootstrap scheduleJobBootstrap = new ScheduleJobBootstrap(createRegistryCenter(), "SCRIPT",
                createJobConfiguration());
        scheduleJobBootstrap.schedule();
    }

    private static CoordinatorRegistryCenter createRegistryCenter()
    {
        CoordinatorRegistryCenter regCenter = new ZookeeperRegistryCenter(
                new ZookeeperConfiguration("localhost:2181", "elastic-job"));
        regCenter.init();
        return regCenter;
    }

    private static JobConfiguration createJobConfiguration()
    {
        // 创建作业配置
        JobConfiguration jobConfig = JobConfiguration.newBuilder("MyScriptJob", 1).cron("0/5 * * * * ?").shardingItemParameters("0=RDP").setProperty(ScriptJobProperties.SCRIPT_KEY,"/Users/dongxiyan/code/job.sh").build();

        return jobConfig;

    }
}
